package cn.hchaojie.camp.day13;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client1 {
	public static void main(String[] args) {
		// host:主机 port：端口
		try (
			Socket socket = new Socket("127.0.0.1", 6666);
			DataOutputStream os = new DataOutputStream(
					new BufferedOutputStream(socket.getOutputStream()));
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in, "utf-8"));
				) {
			
			System.out.println("和服务器已经连上了。。。");
			
			while (true) {
				// 从控制台读取一行文字
				String message = reader.readLine();
				os.writeUTF(message);
				os.flush();
				
				if ("88".equals(message)) {
					break;
				}
			}
			
			System.out.println("客户端结束。。。");
			
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
